#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class Solution{
    public:
    //best--> 递减，则 num[i] - min_num == 0 递增找最大
    int ans1(vector<int>& num){
        int length = num.size();
        int min_num = 1e9, max_num = 0;
        for(int i = 0; i != length; i++){
            if(num[i] - min_num > max_num){
                max_num = num[i] - min_num;
            }
            if(num[i] < min_num){
                min_num = num[i];
            }
        }
        return max_num;
    }

    int ans2(vector<int>& num){
        int length = num.size(), ret = 0;
        for(int i = 0; i != length; i++){
            for(int j = i+1; j != length; j++){
                if((num[j] - num[i]) > ret){
                    ret = num[j] - num[i];
                }
            }
        }
        return ret;
    }
};

void test1(){
    vector<int> num = {7, 1, 5, 3, 6, 4};

    Solution s;
    int ret = s.ans1(num);
    cout << ret << endl;
}

void test2(){
    vector<int> num = {7, 6, 4, 3, 1};

    Solution s;
    int ret = s.ans1(num);
    cout << ret << endl;
}

void test3(){
    vector<int> num = {2, 4, 1};

    Solution s;
    int ret = s.ans1(num);
    cout << ret << endl;
}

int main(void){
    test1();
    test2();
    test3();

    return 0;
}